<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import =  "java.util.HashMap,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.validator.DynaValidatorForm"
%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<script language="JavaScript">

  function onChangeCntType(theForm) {
      theForm.action = '<html-el:rewrite page="/cm/cmCategoryRolePermissionAdd.do"/>';
      theForm.submit();
    return false;
  }
         
  function doValidate(theForm) {
     if (theForm.cntTypeId.value == -1) {
        alert("<bean-el:message bundle='cm.messages' key='error.content.categoryRolePermission.cntTypeId.empty'/>");
        return false;
     }
     if (theForm.categoryPath.value == null || theForm.categoryPath.value.length == 0) {
        alert("<bean-el:message bundle='cm.messages' key='error.content.categoryRolePermission.empty'/>");
        return false;
     }
     if (theForm.createContentPermission.checked == false &&
         theForm.noAccessPermission.checked == false &&
         theForm.editContentPermission.checked == false &&
         theForm.viewContentPermission.checked == false &&
         theForm.deleteContentPermission.checked == false && 
         theForm.browseCategoryPermission.checked == false &&
         theForm.createSubcategoryPermission.checked == false &&
         theForm.modifyCategoryPermission.checked == false ) 
     {
        alert("<bean-el:message bundle='cm.messages' key='cm.content.categoryRolePermission.noPermissionSelected'/>");
        return false;
     }
     if (theForm.noAccessPermission.checked == true &&
         (theForm.createContentPermission.checked == true && 
         theForm.createContentPermission.disabled == false ||
         theForm.editContentPermission.checked == true &&
         theForm.editContentPermission.disabled == false ||
         theForm.viewContentPermission.checked == true && 
         theForm.viewContentPermission.disabled == false ||
         theForm.deleteContentPermission.checked == true && 
         theForm.deleteContentPermission.disabled == false  ||
         theForm.browseCategoryPermission.checked == true && 
         theForm.browseCategoryPermission.disabled == false ||
         theForm.createSubcategoryPermission.checked == true &&
         theForm.createSubcategoryPermission.disabled == false ||
         theForm.modifyCategoryPermission.checked == true && 
         theForm.modifyCategoryPermission.disabled == false )) 
     {
       theForm.createContentPermission.disabled= false;
       theForm.viewContentPermission.disabled= false;
       theForm.editContentPermission.disabled= false;
       theForm.deleteContentPermission.disabled= false;
       theForm.browseCategoryPermission.disabled= false;
       theForm.modifyCategoryPermission.disabled= false;
       theForm.createSubcategoryPermission.disabled= false;
       alert("<bean-el:message bundle='cm.messages' key='cm.content.categoryRolePermission.noAccessExclusive'/>");
       return false;
     }
     return true;
  }

  function doReset(theForm)
  {
     theForm.createContentPermission.disabled= false;
     theForm.viewContentPermission.disabled= false;
     theForm.editContentPermission.disabled= false;
     theForm.deleteContentPermission.disabled= false;
     theForm.browseCategoryPermission.disabled= false;
     theForm.modifyCategoryPermission.disabled= false;
     theForm.createSubcategoryPermission.disabled= false;
     theForm.createContentPermission.checked=theForm.createContentPermission.defaultChecked;
     theForm.viewContentPermission.checked=theForm.viewContentPermission.defaultChecked;
     theForm.editContentPermission.checked=theForm.editContentPermission.defaultChecked;
     theForm.deleteContentPermission.checked=theForm.deleteContentPermission.defaultChecked;
     theForm.browseCategoryPermission.checked=theForm.browseCategoryPermission.defaultChecked;
     theForm.modifyCategoryPermission.checked=theForm.modifyCategoryPermission.defaultChecked;
     theForm.createSubcategoryPermission.checked=theForm.createSubcategoryPermission.defaultChecked;
     theForm.noAccessPermission.checked=theForm.noAccessPermission.defaultChecked;

   return false;

  }

  function setNoAccess(theForm)
  {
    if(theForm.noAccessPermission.checked == true){
     theForm.createContentPermission.disabled= "checked";
     theForm.viewContentPermission.disabled= "checked";
     theForm.editContentPermission.disabled= "checked";
     theForm.deleteContentPermission.disabled= "checked";
     theForm.browseCategoryPermission.disabled= "checked";
     theForm.modifyCategoryPermission.disabled= "checked";
     theForm.createSubcategoryPermission.disabled= "checked";
     theForm.createContentPermission.checked= false;
     theForm.viewContentPermission.checked= false;
     theForm.editContentPermission.checked= false;
     theForm.deleteContentPermission.checked= false;
     theForm.browseCategoryPermission.checked= false;
     theForm.modifyCategoryPermission.checked= false;
     theForm.createSubcategoryPermission.checked= false;
    }
    else{
     theForm.createContentPermission.disabled= false;
     theForm.viewContentPermission.disabled= false;
     theForm.editContentPermission.disabled= false;
     theForm.deleteContentPermission.disabled= false;
     theForm.browseCategoryPermission.disabled= false;
     theForm.modifyCategoryPermission.disabled= false;
     theForm.createSubcategoryPermission.disabled= false;

    }
     return true;
  }

  function doCancel(theForm) {
    if (theForm != null) {
      var cancelAction ='<c:out value="${cmCategoryRolePermissionEditForm.map.cancelAction}"/>';
      theForm.action='<html-el:rewrite page="' + cancelAction + '" />';
      theForm.submit();
      return true;
    }
    return false;
  }

  function doCategorySelect(formName) {
    var thisForm = document.forms[formName];
     if (thisForm.cntTypeId.value == -1) {
        alert("<bean-el:message bundle='cm.messages' key='error.content.categoryRolePermission.cntTypeId.empty'/>");
        return false;
     }
    if (isNaN(thisForm.cntTypeId.value)) {
      doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'selectCategory', 60,null, null,null,null, null, null, null, null, null, false);
    }
    else{
      doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'selectCategory', thisForm.cntTypeId.value,null, null,null, null, null, null, null, null,null, false);
    }
  } 

 function selectCategory(ids, names) {
  var thisForm = document.forms['cmCategoryRolePermissionEditForm'];
  thisForm.selectedCategoryOid.value = ids[0];
  thisForm.categoryPath.value = names[0];
  return false;
} 
  
</script>
<%@include file="/mt/common/pickerPopupHelper.jsp" %>
<jsp:useBean id="cmCntTypeListView" scope="session" type="com.broadvision.web.util.ViewDynaBean"/>

<%
  java.util.HashMap map = new java.util.HashMap();
  DynaValidatorForm cmCategoryRolePermissionEditForm = (DynaValidatorForm) request.getAttribute("cmCategoryRolePermissionEditForm");
  map.put("oid", (Long) PropertyUtils.getSimpleProperty(cmCategoryRolePermissionEditForm, "oid"));
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>


<html-el:form action="/cm/cmCategoryRolePermissionSave.do" >

<html-el:hidden  property="oid" />
<html-el:hidden  property="selectedCategoryOid" />
<html-el:hidden  property="cancelAction" />

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
        <div class="pageTitle">
            <c:out value="${cmCategoryRolePermissionEditForm.map.roleName}"/> 
        </div> 

	<div class="errorMessage"><html-el:errors/></div>
        <%@include file="/mc/common/pagetab.jsp" %>

        <div class="pageSubtitle">

          <span class="left">
	     <c:choose>
		<c:when test="${cmCategoryRolePermissionEditForm.map.selectAction=='ADD'}"> 
                   <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.add"/>
	        </c:when>
		<c:otherwise>
                   <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.edit"/>
		</c:otherwise>
	     </c:choose>
          </span>
          <span class="right">&nbsp;</span>
        </div> 

        <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="doc tyoe permission detail">
          <tr> 
            <td class="label" width="20%">
               <bean-el:message bundle="cm.messages" key="cm.browse.type"/>:
            </td>
            <td class="labelField" width="80%">
	       <c:if test="${cmCategoryRolePermissionEditForm.map.selectAction=='ADD'}"> 
                  <c:set var="cntList" scope="page" value="${cmCntTypeListView.map.cntTypeList}"/>
                   <html-el:select name="cmCategoryRolePermissionEditForm" property="cntTypeId" onchange="onChangeCntType(this.form)"> 
                     <html-el:options collection="cntList" property="id" labelProperty="name" />
                   </html-el:select>
               </c:if>
	    <c:if test="${cmCategoryRolePermissionEditForm.map.selectAction=='EDIT'}">
            <c:choose>
	    <c:when test="${cmCategoryRolePermissionEditForm.map.cntTypeName=='BV_CNT_SVCS'}">
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.doctype"/>:
            </c:when>
            <c:otherwise>
                <c:out value="${cmCategoryRolePermissionEditForm.map.cntTypeName}" />
	    </c:otherwise>
            </c:choose>
                <html-el:hidden property="cntTypeName" />
                <html-el:hidden property="cntTypeId" />
	    </c:if>
	   </td>
          </tr> 
          <tr> 
            <td class="label" width="20%">
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.category"/>:
	   </td>
            <td class="labelField" width="80%">
	    <c:if test="${cmCategoryRolePermissionEditForm.map.selectAction=='ADD'}">
                  <html-el:text size="50" maxlength="80" property="categoryPath" readonly="true"/> &nbsp;
                  <input type="button" name="browseCategory" class="pageButton" 
                    onClick="JavaScript:doCategorySelect('cmCategoryRolePermissionEditForm')" 
                    value='<bean-el:message bundle="cm.messages" key="button.browse"/>'>
	    </c:if>
	    <c:if test="${cmCategoryRolePermissionEditForm.map.selectAction=='EDIT'}">
                <c:out value="${cmCategoryRolePermissionEditForm.map.categoryPath}" />
                <html-el:hidden property="categoryPath" />
                <html-el:hidden property="categoryPathId" />
                <html-el:hidden property="selectAction" value="EDIT" />
	    </c:if>
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox name="cmCategoryRolePermissionEditForm" property="noAccessPermission" onclick="setNoAccess(this.form)" />
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.noAccessAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox name="cmCategoryRolePermissionEditForm" property="createContentPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.createContentAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="editContentPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.editContentAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="viewContentPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.viewContentAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="deleteContentPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.deleteContentAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="browseCategoryPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.browseCategoryAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="modifyCategoryPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.modifyCategoryAction"/>:
            </td>
          </tr>
          <tr> 
            <td class="labelField" width="20%">
		&nbsp;&nbsp
            </td>
            <td class="labelField" width="80%">
              <html-el:checkbox   name="cmCategoryRolePermissionEditForm" property="createSubcategoryPermission"/>
              <bean-el:message bundle='cm.messages' key="cm.content.categoryRolePermission.createSubcategoryAction"/>:
            </td>
          </tr>
        </table>

        <div class="pageButtonWrap" align="right">
	   <html-el:button styleClass="inputButton" property="resetBtn" onclick="return doReset(this.form)">
             <bean-el:message bundle='cm.messages' key="button.reset"/>
           </html-el:button>
          <html-el:img page="/cm/images/build/transparent.gif" width="10" height="1" border="0" alt=""/>
          <html-el:button styleClass="inputButton" property="cancelBtn" onclick="return doCancel(this.form)">
            <bean-el:message bundle='cm.messages' key="button.cancel"/>
          </html-el:button>
          <html-el:submit styleClass="inputButton" property="submitBtn" onclick="return doValidate(this.form)">
            <bean-el:message bundle='cm.messages' key="button.save"/>
          </html-el:submit>
        </div>
    </td>
  </tr>
</table>

</html-el:form>
